package com.mashibing.juc.c_002;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName T01
 * @Description 模拟控制线程
 * @Author xiongwei.wu
 * @Date 2021/7/1 10:54
 **/
public class T01 {
    //对比一下有无volatile的情况下，整个程序运行结果的区别
    /*volatile*/ boolean running = true;

    void m() {
        System.out.println("m start");
        while (running) {
//            try {
//                TimeUnit.SECONDS.sleep(2);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
        System.out.println("m end");
    }

    public static void main(String[] args) {
        T01 t = new T01();
        new Thread(t::m, "t1").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        t.running = false;
    }
}
